<?php

namespace app\common\model;

use think\Model;

/**
 * Car
 */
class CarView extends Car
{
    public function getCarTypeAttr($value)
    {
        $status = [1 => '手动挡',2 => '自动挡'];
        return $status[$value];
    }

    public function getPowerTypeAttr($value)
    {
        $status = [1 => '汽油',2 => '柴油',3 => '纯电',4 => '插混',5 => '增程'];
        return $status[$value];
    }

    public function getCarLicenseAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            $value = explode(',', $value);
        }
        $status = [1 => 'C1',2 => 'C2',3 => 'A1',4 => 'A2',5 => 'B1',6 => 'B2'];
        $datas = [];
        foreach ($value as $v){
            $datas[] = $status[$v];
        }
        return $datas;
    }

    public function getStaetsAttr($value): string
    {
        if((string)intval($value) == $value){
            return (string)$value.'座';
        }
        return $value;
    }

    public function getImageAttr($value): string
    {
        if(empty($value)) return "";
        return env('FIEL_PATH').$value;
    }

    public function getImagesAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            $value = explode(',', $value);
        }
        foreach ($value as &$v){
            $v = env('FIEL_PATH').$v;
        }
        return $value;
    }
}